package com.example.administrator.xiaobo.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.adapter.MyViewpagerAdapter;
import com.example.administrator.xiaobo.activity.SettingsActivity;
import com.example.administrator.xiaobo.fragment.MineDetailsFragment.AboutFragment;
import com.example.administrator.xiaobo.fragment.MineDetailsFragment.AttrgFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MineFragment extends Fragment {
    public static final String TAG = "MineFragment";


    private ImageView image, imagebtn;
    private TextView name;

    private RelativeLayout rl,rl_delete;
    private TabLayout tab;
    private ViewPager viewpager;
    private List<Fragment> data;

    public MineFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootview = inflater.inflate(R.layout.fragment_mine, container, false);
        init(rootview);
        initin(rootview);
        return rootview;
    }

    private void init(View rootview) {
        image = ((ImageView) rootview.findViewById(R.id.iv_icon));
        name = ((TextView) rootview.findViewById(R.id.textuser_name));
        imagebtn = (ImageView) rootview.findViewById(R.id.iv_setting);
        imagebtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(), SettingsActivity.class));

            }
        });
        rl = (RelativeLayout) rootview.findViewById(R.id.login_relative);
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "第三方登录", Toast.LENGTH_SHORT).show();
            }
        });

    }


    private void initin(View v) {
        tab = ((TabLayout) v.findViewById(R.id.tab));
        viewpager = ((ViewPager) v.findViewById(R.id.viewpager));
        String[] title = new String[]{"关注主播", "观看历史"};
        data = new ArrayList<>();
        data.add(new AboutFragment());
        data.add(new AttrgFragment());
        MyViewpagerAdapter adapter = new MyViewpagerAdapter(getChildFragmentManager(), title, data);
        viewpager.setAdapter(adapter);
        tab.setupWithViewPager(viewpager);


    }

}
